﻿namespace Kwan.Cache
{
    using System;
    using System.Web.Caching;

    public class CacheDependencyInfo
    {
        public double CacheMinutes;
        public int CallCount;
        public DateTime CreaeTime;
        internal bool SetChange;
        private DateTime cacheTime = DateTime.MinValue;
        private CacheDependency cacheDependency;

        public CacheDependencyInfo(CacheDependency dependency, double cacheMinutes)
        {
            if (dependency != null)
            {
                this.cacheDependency = dependency;
                this.cacheTime = this.cacheDependency.UtcLastModified;
            }
            this.CreaeTime = DateTime.Now;
            this.CacheMinutes = cacheMinutes;
        }

        public void UserSetChange(bool change)
        {
            this.SetChange = !this.IsChanged && change;
        }

        public bool IsChanged
        {
            get
            {
                if ((this.cacheDependency == null) || (!this.cacheDependency.HasChanged && !(this.cacheTime != this.cacheDependency.UtcLastModified)))
                {
                    return false;
                }
                this.cacheTime = this.cacheDependency.UtcLastModified;
                return true;
            }
        }
    }
}

